<?php //$Id: lib.php 94 2006-12-10 21:56:21Z heinz $



/**
 * Generates the wrapper for the flash file
 *
 * Parameters:
 * $dir: lps-directory
 * $url: Red5-Server-URL
 * $ticket: the session token, unique string
 * $invitor: the session invitor
 * $invitees: comma separated list of invited parties' uids
 * $role: invitor or invitee
 *
 */
function get_flashwrapper($dir, $url, $ticket, $invitor, $invitees, $role, $moderated) {

  if( $role=="invitor" ) {
      $inviteesString='&inviteesNames='.cov_getusername($invitees);
  } else {
    $inviteesString="";
  }

  return '
<!DOCTYPE html
  PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <link rel="SHORTCUT ICON" href="http://www.laszlosystems.com/favicon.ico"><title>Covcell audio/video chat</title><script type="text/javascript">
          // If loaded bare into a browser, set the browser size to the canvas size
          if (window === top) {
            (function (width, height) {
              // Cf. http://www.quirksmode.org/viewport/compatibility.html
              if (window.innerHeight) {
                // Sadly, innerHeight/Width is not r/w on some browsers, and resizeTo is for outerHeight/Width
                window.resizeTo(width ? (width + window.outerWidth - window.innerWidth) : window.outerWidth,
                                height ? (height + window.outerHeight - window.innerHeight) : window.outerHeight);
              } else if (document.documentElement && document.documentElement.clientHeight) {
                if (width) {
                  document.documentElement.clientWidth = width;
                }
                if (height) {
                  document.documentElement.clientHeight = height;
                }
              } else {
                if (width) {
                  document.body.clientWidth = width;
                }
                if (height) {
                  document.body.clientHeight = height;
                }
              }
            })(null, null);
          }
        </script><script type="text/javascript">
            lzOptions = { ServerRoot: \'\'};
        </script><script type="text/javascript" src="'.$dir.'/lps/includes/embed-compressed.js"></script><style type="text/css">
        	html, body
        	{
        		/* http://www.quirksmode.org/css/100percheight.html */
        		height: 100%;
        		/* prevent scrollbars */
        		margin: 0;
        		padding: 0;
        		border: 0 none;
        		overflow: hidden;
        	}
        	body {
                background-color: #ffffff;
            }
        	
        	img { border: 0 none; }
        </style></head><body><script type="text/javascript">
              Lz.swfEmbed({url: \''.$dir.'/CovcellAVChat.lzx.swf?&url='.urlencode($url).'&ticket='.$ticket.'&userName='.cov_getusername($invitor).$inviteesString.'&role='.$role.'&moderated='.$moderated.'&lzproxied=false\', bgcolor: \'#ffffff\', width: \'100%\', height: \'100%\', id: \'lzapp\', accessible: \'false\'});
            </script><noscript>
            Please enable JavaScript in order to use this application.
        </noscript></body></html>
';
}


/**
 * Get user first and last name from Moodle DB.
 * @param int $userid Comma-separated list of userids.
 * @return mixed False if userid list empty, otherwise list of usernames raw encoded for URL.
 */
function cov_getusername($userid)
{
	global $db, $CFG;
	$usernames = "";
	
// 	if( !$userid_arr = explode(",", $userid) )
// 		return false; // List was empty.
		
// 	$itemcnt = count($userid_arr);
	
// 	for($i = 0; $i < $itemcnt; $i++) {
// 		$userSQL = 'SELECT firstname,lastname FROM '.$CFG->prefix.'user WHERE id='.$userid_arr[$i];
	
// 		if (!$rs = $db->Execute($userSQL)) {
//         	if (isset($CFG->debug) and $CFG->debug > 7) {
//             	notify($db->ErrorMsg() .'<br /><br />'.$userSQL);
//         	}
//         	if (!empty($CFG->dblogerror)) {
//             	$debug=array_shift(debug_backtrace());
//             	error_log("SQL ".$db->ErrorMsg()." in {$debug['file']} on line {$debug['line']}. STATEMENT:  $userSQL");
//         	}
//         	return false;
//     	}
//     	// TODO Not sure if %20 is correct encoding for ws. [hgk]
//     	// TODO What happens if only first OR last name specified? [hgk]
//     	if( $i == 0 ) {
//     		$usernames .= $rs->firstname.' '.$rs->lastname;
//     	} else {
//     		$usernames .= ','.$rs->firstname.' '.$rs->lastname;
//     	}
// 	} 
//    return rawurlencode($usernames);
        return $userid;
        
}

?>